<%@page import="com.wowangz.cms.common.utils.SysConstant.CommonUsedStatus"%>
<%@page import="com.wowangz.cms.common.utils.SysConstant.Templatetype"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/pageHead.jsp"%>
<script type="text/javascript">
	function view(val){
		var id = val;
		$(this).isswindow({
			noheader : true,
			url :"${systemctx}/systemmanage/sms/smsSet/smsSetView.web?id="+id
		});
	}
	function addInfo(){
		$(this).isswindow({
			noheader : true,
			url :"${systemctx}/systemmanage/sms/smsSet/toSmsSetPage.web"
		});
	}
	
	function smsSetDelete(id,status){
		if(status == <%=SysConstant.CommonUsedStatus.START%>){
			alert("<%=MessageResourcesUtils.getMessage(request, "systemmanage.sms.alert10")%>");
			return;
		}
		if(confirm('<%=MessageResourcesUtils.getMessage(request, "alertinfo.common.jsp.alert2")%>')){
			// 显示进度条
			showSending();
			$.get('${systemctx}/systemmanage/sms/smsSet/smsSetDelete.json?id=' + id,function(data){
				//关闭执行...
				closeSending();
				data = jQuery.parseJSON(data);
				if(data.messagetype == 1){
					alert(data.message);
					$('#datagrid').datagrid('load',$('#form1').serializeObject());
				}else {
					alert(data.message);
					return ;
				}
			});
		}
	}
	function startAndStop(message,used){
		var rows = $('#datagrid').datagrid('getSelections');
		if(rows.length == 0) {
			alert("<%=MessageResourcesUtils.getMessage(request, "alertinfo.common.jsp.alert5")%>");
			return ;
		} 
		var row = rows[0];
		if(row.used == <%=SysConstant.CommonUsedStatus.START%> && row.used == used){
			alert("<%=MessageResourcesUtils.getMessage(request, "systemmanage.sms.alert8")%>");
			return;
		} else if(row.used == <%=SysConstant.CommonUsedStatus.STOP%> && row.used == used){
			alert("<%=MessageResourcesUtils.getMessage(request, "systemmanage.sms.alert9")%>");
			return;
		}
		if(confirm(message)){
			var id = row.id;
			// 显示进度条
			showSending();
			$.get('${systemctx}/systemmanage/sms/smsSet/startAndStop.json?id=' + id + '&used=' + used,function(data){
				//关闭执行...
				closeSending();
				data = jQuery.parseJSON(data);
				if(data.messagetype == 1){
					alert(data.message);
					$('#datagrid').datagrid('load',$('#form1').serializeObject());
				}else {
					alert(data.message);
					return ;
				}
			});
		}
	}
	
	function query_datagrid(){
		//加载分页控件 datagrid
		$('#datagrid').issdatagrid({
			formid : 'form1',
			title : '<%=MessageResourcesUtils.getMessage(request, "systemmanage.sms.list.title")%>',
			singleSelect : true,
			striped : true,
			url : '${systemctx}/systemmanage/sms/smsSet/smsSetList.json',
			sortName: 'modifytime',
			sortOrder: 'desc',
			remoteSort : true,
			idField : 'id',
			rownumbers : true,
			queryParams:$('#form1').serializeObject(),
			frozenColumns :[[
 				/* {field:'ck', checkbox:true}, */
 				{field : 'id',title : '<%=MessageResourcesUtils.getMessage(request, "common.button.operation")%>',align : 'center',formatter : function(value,row,index) {
 						var str = '';	
 						str += '<a href="javascript:void(0);" class="easyui-linkbutton" onclick="smsSetEdit(' + row.id + ')"><%=MessageResourcesUtils.getMessage(request,"common.button.update") %></a> ';
		      			str += '<a href="javascript:void(0);" class="easyui-linkbutton" onclick="smsSetDelete(' + row.id + ',' + row.used + ')"><%=MessageResourcesUtils.getMessage(request,"common.button.delete") %></a> ';
		    			return str;
	    			}
	        	},
 				{title : '<%=MessageResourcesUtils.getMessage(request,"systemmanage.sms.column.templatecode")%>',field : 'templatecode',sortable : true,width:200,align : 'left',formatter: function(value,row,index){
 					 	  return "<a href=\"javascript:void(0);\" onclick=\"view('"+row.id+"')\">"+value+"</a>";
 					  }
 				},  
 				{title : '<%=MessageResourcesUtils.getMessage(request,"systemmanage.sms.column.tamplatecontent")%>',field : 'templatecontent',sortable : true,align : 'left',width:540}, 
 				{title : '<%=MessageResourcesUtils.getMessage(request,"systemmanage.sms.column.templatetype")%>',field : 'templatetype',sortable : true,align : 'left',width:120}, 
 			]],
 			columns : [[  
              	{title : '<%=MessageResourcesUtils.getMessage(request,"systemmanage.sms.column.used")%>',field : 'usedname',sortable : true,align : 'center'} 
            ]],
			onLoadSuccess : function(data) {

			}
		});
	}
	$(document).ready(function() {
		query_datagrid();
		$('#butQuery').click(function() {
			var parentcolumnname = $("#parentcolumnname").val();
			if(parentcolumnname==''){
				$('#parentcolumn').val('');
			}
			$('#datagrid').datagrid('load',$('#form1').serializeObject());
		});
		$("#templatetype").selectutil({
			optModel :<%=SysConstant.Templatetype.getModelJSONString(true, false)%>,
			optDefault :''
		});
		$("#used").selectutil({
			optModel :<%=SysConstant.CommonUsedStatus.getMode1JSONString(true, false)%>,
			optDefault :''
		});
	});
	
	function smsSetEdit(id){
		$(this).isswindow({
			noheader : true,
			url :'${systemctx}/systemmanage/sms/smsSet/smsSetEdit.web?id='+id
		});
	}
	
</script>
<form action="" id="form1" name="form1">
	<div class="pageMain">
		<div class="pageTitle">
			<%=MessageResourcesUtils.getMessage(request, "systemmanage.bascsetting.title")%>
			<span></span>
			<%=MessageResourcesUtils.getMessage(request, "systemmanage.sms.title") %>
			<span></span>
			<%=MessageResourcesUtils.getMessage(request, "systemmanage.sms.list.title")%>
		</div>
		<div class="pageBody">
			<div class="form-group">
				<ul>
					<li>
						<i></i> 
						<label>
							<!-- 是否显示 -->
							<%=MessageResourcesUtils.getMessage(request, "systemmanage.sms.column.templatetype") %>
						</label>
						<span>
							<select name="templatetype" id="templatetype"></select>
						</span>
					</li>
					<li>
						<i></i>
						<label>
							<%=MessageResourcesUtils.getMessage(request, "systemmanage.sms.column.used") %>
						</label>
						<span>
							<select name="used" id="used"></select>
						</span>
					</li>
				</ul>
			</div>
		</div>
		<div class="button-group">
			<input type="button" class="btn btn-default" id="butQuery" value="<%=MessageResourcesUtils.getMessage(request,"common.button.query") %>" />
			<input type="button" class="btn btn-default" onclick="addInfo()" value="<%=MessageResourcesUtils.getMessage(request,"common.button.add") %>" />
			<input type="button" class="btn btn-default" onclick="startAndStop('<%=MessageResourcesUtils.getMessage(request, "systemmanage.sms.alert5") %>','<%=SysConstant.CommonUsedStatus.START %>')" value="<%=MessageResourcesUtils.getMessage(request,"systemmanage.sms.button.start") %>" />
			<input type="button" class="btn btn-default" onclick="startAndStop('<%=MessageResourcesUtils.getMessage(request, "systemmanage.sms.alert6") %>','<%=SysConstant.CommonUsedStatus.STOP %>')" value="<%=MessageResourcesUtils.getMessage(request,"systemmanage.sms.button.stop") %>" />
			<input type="button" class="btn btn-default" id="sendMessage" value="发送短信 " />
		</div>
		<table style="width: 100%">
			<tr>
				<td>
					<table id="datagrid"></table>
				</td>
			</tr>
		</table>				
	</div>
</form>
<script type="text/javascript">
	$(function(){
		$("#sendMessage").click(function(){
			var rows = $('#datagrid').datagrid('getSelections');
			if(rows.length > 0){
				var ids = "";
				for(var i = 0; i < rows.length; i++){
					var id = rows[i].id;
					if(i < rows.length - 1){
						ids += id + ",";
					} else {
						ids += id;
					}
				}
				$.getJSON("${systemctx}/systemmanage/sms/smsSet/testSendMessage.web?ids="+ids,function(data) {
					if(data.code == 1){
						alert(data.message);
					} else {
						alert(data.message);
						return ;
					}
				})
			} else {
				alert('请选择一条数据')
			}
		});
	})
</script>

<%-- 引入页面尾 --%>
<%@ include file="/pageFloor.jsp"%>